package cn.tedu.micro.demo.es;

import cn.tedu.micro.demo.es.po.StudentEsPO;
import cn.tedu.micro.demo.es.repository.StudentEsRepository;
import cn.tedu.micro.demo.es.utils.ParseDateUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;

import java.util.Date;
import java.util.List;

@SpringBootTest
public class EsTestDemo02 {
    @Autowired
    private StudentEsRepository studentEsRepository;
    //派生1: findByName
    @Test
    public void findByName(){
        List<StudentEsPO> students = studentEsRepository.getByName("雨");
        for (StudentEsPO student : students) {
            System.out.println(student);
        }
    }
    //派生2: findByNameOrAge
    @Test
    public void findByNameOrAge(){
        List<StudentEsPO> students = studentEsRepository.getByNameOrAge("诸葛", 18);
        for (StudentEsPO student : students) {
            System.out.println(student);
        }
    }
    //派生3: findByNameOrAgeLessThan
    @Test
    public void findByNameOrAgeLessThan(){
        List<StudentEsPO> students = studentEsRepository.getByNameOrAgeLessThan("诸葛", 20);
        for (StudentEsPO student : students) {
            System.out.println(student);
        }
    }
    //派生4: findByIdIn
    @Test
    public void findByIdIn(){
        List<StudentEsPO> students = studentEsRepository.getByIdIn(List.of(
                "2b41662e-bb23-4655-b7d4-78a76fe53002","782ea3d4-d043-4ea7-9731-7e14c7eed69a"));
        for (StudentEsPO student : students) {
            System.out.println(student);
        }
    }
    //派生5: findByBirthdayBetween
    @Test
    public void findByBirthdayBetween(){
        List<StudentEsPO> students = studentEsRepository.getByBirthdayBetween(
                ParseDateUtil.parse("2000-01-01 00:00:00"),
                ParseDateUtil.parse("2002-12-31 23:59:59"));
        for (StudentEsPO student : students) {
            System.out.println(student);
        }
    }
    //派生6: findByAgeLessThanOrderByBirthdayDesc
    @Test
    public void findByAgeLessThanOrderByBirthdayDesc(){
        List<StudentEsPO> students = studentEsRepository.getByAgeLessThanOrderByBirthdayDesc(25);
        for (StudentEsPO student : students) {
            System.out.println(student);
        }
    }
    //派生7: findByLocationWithin
    @Test
    public void findByLocationWithin(){
        List<StudentEsPO> students = studentEsRepository.getByLocationWithin(
                new GeoPoint(0, 0),
                new Distance(100, Metrics.KILOMETERS));
        for (StudentEsPO student : students) {
            System.out.println(student);
        }
    }
}
